#include "UDPServe.hpp"
#include "Dict.hpp"

std::string defaulthandle(const std::string& message)
{
    std::string hello="hello";
    hello+=message;
    return hello;
}

int main(int argc,char*argv[])
{
    // if(argc!=3)//一会改一下
    if(argc!=2)
    {
        std::cerr<<"Usage:"<<argv[0]<<" Port"<<std::endl;
        return 1;
    }
    
    // std::string ip=argv[1];
    uint16_t port=std::stoi(argv[1]);
    Enable_Console_Sync_Strategy;
    
    Dict* dict=new Dict();
    dict->LoadDictionary();

    // std::unique_ptr<UdpServe> m = std::make_unique<UdpServe>(defaulthandle,port);
    std::unique_ptr<UdpServe> m = std::make_unique<UdpServe>(port,[&dict](const std::string&word,InetAddr&cli){
        return dict->Translate(word,cli);
    });

    m->Init();
    m->Start();
    return 0;    
}